import app from "../../../app";
import { prop_min_type } from "../../../shared/interface";
import { Tpl_attribute, Tpl_attribute_pet, template } from "../../../shared/master/MsgAction";
import word from "../../word/word";
import { SKILL } from "../skill/SK_active";
import { _Cls_Points } from "./att/_Points";
import { _Cls_Att } from "./att/_Att";
import { CreateBody_base, baseBody } from "./baseBody";
import { player } from "./player";
export interface CreateBody_pet extends CreateBody_base {

}
/**
 * 永久类召唤物
 */
export class pet extends baseBody {
    icon: string = '🦄';
    private _parent?: baseBody;
    constructor() {
        super()
        this.setBodyType('pet')
    }
    getMsgAttTpl() {
        this.update_attributes();
        let p = new _Cls_Points();
        p.add(this.P);
        p.add(this.Job);


        let att = new _Cls_Att();
        att.reset(this._attributes);
        let tpl: Tpl_attribute_pet = {
            render_type:'pet_concise',
            name: this.name,
            hp_now: this.Hp_now,
            score:this.getScore(),
            mp_now: this.Mp_now,
            leve: this.leve,
            Points: p,
            attributes: att,
            body_type: "pet",
            style_id: this.style_id
        }
        return {template:template.attribute_pet,data:tpl};
    }
    reName(n:string){
        this.name = n;
        this.createCfg.name = n;
    }
    reload(data: pet) {
        let _data: any = data;
        const jumpKey = [ 'P', 'skills_body', 'equip_ordinary', 'pets', 'bag','Talent','Job']
        for (const key in data) {
            if (key.startsWith('_')) {
                continue;
            }
            if (jumpKey.includes(key)) {
                continue;
            }
            console.log(key, typeof (key))
            this[key] = _data[key]
        }
        for (let i = 0; i < data.skills_body.length; i++) {
            let sk = new SKILL(_data.skills_body[i])
            this.skills_body.push(sk)
        }
        this.P.reset(data.P);
        this.Job.reset(data.Job);
        this.Talent.reset(data.Talent)
        this.init();
    }
    set_Master(tag: baseBody) {
        this._parent = tag;
    }
    get_Master() {
        return this._parent || this;
    }
    async sendMsg(tel: template, data?: any) {
        if (!(this._parent instanceof player)) {
            return;
        }
        switch (tel) {
            case template.default:
                data = `[宠物]${data}`
                break;

            default:
                break;
        }
        this._parent.sendMsg(tel, data)
    }
    getBag() {
        if (!(this._parent instanceof player)) {
            return;
        }
        return this._parent.getBag()
    }

}